package com.h6.crm.config;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.h6.crm.interceptor.ResponseResultInterceptor;
import com.h6.crm.interceptor.UserLoginInterceptor;
import com.h6.crm.resolver.LoginUserResolver;

import org.springframework.lang.NonNull;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    ResponseResultInterceptor interceptor;

    @Autowired
    UserLoginInterceptor userLoginInterceptor;

    @Autowired
    LoginUserResolver loginUserResolver;

    @Override
    public void addInterceptors(@NonNull InterceptorRegistry registry) {
        registry.addInterceptor(userLoginInterceptor);
        registry.addInterceptor(interceptor);
        WebMvcConfigurer.super.addInterceptors(registry);

    }

    @Override
    public void addArgumentResolvers(@NonNull List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(loginUserResolver);
    }

}
